import {BasicColumn, FormSchema} from '@/components/table';
import {RenderType} from '@pkg/setting';
import {rules} from '@pkg/utils';
import {Api} from './api';
import {render} from '@/hooks/render/renderUtils';
export const columns: BasicColumn[] = [
  {
    title: '头像',
    dataIndex: 'avatar',
    width: 80,
    renderType: RenderType.AVATAR,
  },
  {
    title: '登录账号',
    dataIndex: 'accountName',
    width: 100,
  },
  {
    title: '姓名',
    dataIndex: 'nickName',
    width: 150,
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
    width: 120,
  },
  {
    title: '性别',
    dataIndex: 'sex',
    width: 60,
    dictCode: 'sex',
    renderType: RenderType.DICT,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 50,
    sorter:true,
    renderApi: Api.setUserStatus,
    rowKey: 'userId',
    customRender: render.renderSwitch
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 180,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'accountName',
    label: '登录账号',
    component: 'Input',
    colProps: {span: 4},
  },
  {
    field: 'mobile',
    label: '手机号',
    component: 'Input',
    colProps: {span: 4},
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    colProps: {span: 3},
    componentProps: {
      options: [
        {label: '禁用', value: 0},
        {label: '启用', value: 1}
      ],
    },
  }
];

export const formSchema: FormSchema[] = [
  {
    field: 'nickName',
    label: '姓名',
    component: 'Input',
    required: false,
  },
  {
    field: 'accountName',
    label: '登录账户',
    component: 'Input',
    required: false,
    dynamicDisabled: ({values}) => {
      return values.userId != null
    },
  },
  {
    field: 'password',
    label: '登录密码',
    component: 'InputPassword',
    rules: rules.required(8, 20),
    ifShow: ({values}) => {
      return values.userId == null
    },
  },
  {
    field: 'sex',
    label: '性别',
    component: 'ApiSelect',
    required: false,
    componentProps: {
      dictCode: 'sex',
      stringToNumber: true,
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    required: false,
  },
];

export const changeMobileFormSchema: FormSchema[] = [
  {
    field: 'userId',
    label: '用户Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'mobile',
    label: '会员手机号',
    component: 'Input',
    rules: [
      {required: true, message: '请输入手机号'},
      {pattern: /^1[3456789]\d{9}$/, message: '手机号码格式错误！'},
    ],
  },
];

export const importFormSchema: FormSchema[] = [];
